package com.gigmissions.client.ui;


import java.util.List;

import com.gigmissions.client.config.GigMissionsImageProvider;
import com.gigmissions.client.config.GigMissionsImages;
import com.gigmissions.client.config.GigMissionsMessages;
import com.gigmissions.client.dto.Artist;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class ActivityPanel extends VerticalPanel {
	
	private GigMissionsMessages messages;
	private FlexTable flexTable;
	private GigMissionsImages images;
	private Image icon;
	
	@Inject
	public ActivityPanel(Image icon,GigMissionsImages images,GigMissionsMessages messages,FlexTable flexTable){
		this.flexTable = flexTable;
		this.messages = messages;
		this.images = images;
		this.icon = icon;
		 buildUI();
	}

	
	public void presentArtists(List<Artist> artists){
		
		if(artists==null||artists.size()==0){
			this.add(new Label(messages.noArtists()));
		}else{
			int rowCount = 1;
		    for(Artist artist : artists){
		    	
		    	icon.setResource(GigMissionsImageProvider.getImage(images, artist.getImageType()));
		    	flexTable.setWidget(rowCount, 0, icon);
		    	flexTable.setWidget(rowCount, 1, new Label(artist.getName()));
		    	flexTable.setWidget(rowCount, 2, new Label(String.valueOf(artist.getPoints())));
		    	rowCount++;
		    }
		}
		
	}
	
	public void buildUI(){
		
		
		FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
		flexTable.addStyleName("cw-FlexTable");
		flexTable.setWidth("32em");
		flexTable.setCellSpacing(5);
		flexTable.setCellPadding(3);
		cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
		flexTable.setHTML(0, 0, messages.gigScene());
		cellFormatter.setColSpan(0, 0, 3);
		flexTable.setWidget(0, 1, new Label("This is a spot for ads :)"));
	    cellFormatter.setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
		add(flexTable);
		
	}
			
}
